package com.sms.user;

import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import com.sms.DB.OperateDB;

public class Student {
	private String sno;
	private String sname;
	private String sex;
	private String type;//学生的类型，前台 or 后台
	private String major;
	private String tname;//学生的指导老师的名字
	private String password;
	private int itemCount;//学生所参加的项目总数
	
	//初始化一个学生的信息
	public void init(Map map) {
		this.setSno((String)map.get("sno"));
		this.setSname((String)map.get("sname"));
		this.setSex((String)map.get("sex"));
		this.setPassword((String)map.get("passkey"));
		this.setType((String)map.get("stu_type"));
		this.setMajor((String)map.get("major"));
		this.setTname(this.getTname((String)map.get("tno")));
		this.setItemCount((String)map.get("sno"));
	}
	
	//获取学生指导老师的名字
	public String getTname(String tno) {
		String sql = "select * from teacherinfo where tno = " + tno;
		String name = "";
		List<Map> list = new ArrayList<Map>();
		
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {
			Map map = list.get(0);
			name = (String)map.get("tname");//获取老师的名字
		}
		return name;
	}
	
	public int getItemCount() {
		return itemCount;
	}

	//获取学生参加的项目数并设置相应的属性 
	public void setItemCount(String sno) {
		String sql = "select count(*) as number from groupmember" + 
		" where memberid = '" + sno +  "' " ;
		List<Map> list = new ArrayList<Map>();
		int count = 0;
		
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {
			Map map = list.get(0);
			count = Integer.parseInt(map.get("number").toString());
		}
		
		this.itemCount = count;
	}
	
	public String getSno() {
		return sno;
	}
	
	public void setSno(String sno) {
		this.sno = sno;
	}
	
	public String getSname() {
		return sname;
	}
	
	public void setSname(String sname) {
		this.sname = sname;
	}
	
	public String getSex() {
		return sex;
	}
	
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public String getType() {
		return type;
	}
	
	public void setType(String type) {
		this.type = type;
	}
	
	public String getMajor() {
		return major;
	}
	
	public void setMajor(String major) {
		this.major = major;
	}
	
	public String getTname() {
		return tname;
	}
	
	public void setTname(String tname) {
		this.tname = tname;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
}
